package leetcode;

import org.junit.Test;

/**
 * @author cino
 * justCode
 */
public class leetcode58 {

    @Test
    public void test(){
        String s = "What? Hello";
        System.out.println(lengthOfLastWord(s));
    }


    public int lengthOfLastWord(String s){
        int len = 0 ;
        for (int i = s.length() - 1;i>=0;i--){
            if (s.charAt(i) != ' '){
                len++;
            }else {
                if (len != 0){
                    //最后一个单词获取完了
                    return len;
                }
            }
        }
        return len;
    }
}
